import objects.*;
import base.*;
import ui.*;
import mx.utils.Delegate;
class objects.plugins extends base.base
{
	private var container:MovieClip;
	private var interval:Number;
	//properties
	private var pluginName:String;
	public var isSelected:Boolean = false;
	public var doItNow:Boolean = false;
	public var pluginNum:Number;
	static var pluginWidth:Number;
	static var pluginHeight:Number;
	static var boxX:Number;
	static var boxY:Number;
	static var boxHeight:Number;
	static var boxWidth:Number;
	static var radius:Number = 0;
	//properties common to all plugins
	static var speed:Number = 0.1;
	static var count:Number = 0;
	static var slowSpeed:Number = 0.1;
	static var fastSpeed:Number = 0.5;
	static var sortSpeed:Number = 0.4;
	//random
	private var action:String;
	private var isDone:Boolean = true;
	public var listener:Object = {};
	static var broadCaster:Object = {};
	static var thePlugins:Array = new Array();
	static var pluginObject:Object = new Object();

	static var rolledOn:Number;
	static var pressedOn:Number;
	//
	//
	//
	static function initialiseBroadcaster()
	{
	   	AsBroadcaster.initialize(broadCaster);
	}
	public function plugins (__name:String)
	{
		thePlugins[count] = __name;
		pluginObject[__name] = this
		count ++;
		pluginNum =  count;
		pluginName = __name;

		//trying to make it so that everytime the broadcaster calls "onRoll", they change colour accordingly.
		broadCaster.addListener(listener);
		listener.onRoll = function()
		{
			//how do I access the plugin though, that's what seems to be my issue...
			//cause using "this" doesn't work...
			if (plugins.pressedOn == this.pluginNum)
			{
				this.recolour("selected")
			}
			else
			{
				if (plugins.rolledOn = this.pluginNum)
				{
					this.recolour("hover")
				}
				else
				{
					this.recolour("normal")
				}
			}
		}

	}
	//
	//
	static function createClips ()
	{
		pluginWidth = 200;
		boxHeight = 33;
		boxWidth = pluginWidth / 1.1;
		for (var i:Number = 0; i < thePlugins.length; i++)
		{
			var nextPlugin:Object = pluginObject[thePlugins[i]];
			var plName:String = nextPlugin.pluginName;
			_root.createEmptyMovieClip ("plugin_" + plName, i);
			pluginObject[thePlugins[i]].createContainer ();
		}
	}
	function createContainer ()
	{
		container = _root["plugin_" + pluginName];
		container.createEmptyMovieClip ("base", 2);
		shapes.createShape ("rectangle", container.base, 0, 0, boxWidth, boxHeight, radius, white, 20, false, true, 1, black);
		container._x = (pluginWidth+20);
		container._y = (boxHeight+20)*pluginNum;
		setEvents (pluginNum);
	}
	//
	//
	private function setEvents (plugin:Number)
	{
		container.base.onRollOver = function ()
		{
			plugins.rolledOn = plugin;
			plugins.broadCaster.broadcastMessage("onRoll");
		};
	}
	//
	//
	function createShape (fillColour:Number, fillAlpha:Number, textColour:Number)
	{
		shapes.createShape ("rectangle", container.base, 0, 0, boxWidth, boxHeight, radius, fillColour, fillAlpha, false, true, 1, black);
		container.label_txt.textColor = textColour;
	}
	function reColour (__action:String)
	{
		if (__action == "normal")
		{
			createShape (white, 26, black);
		}
		else if (__action == "selected")
		{
			createShape (red, 26, black);
		}
		else if (__action == "hover")
		{
			createShape (blue, 26, black);
		}
	}
}

